package com.g3.zoosite.service.impl;

import com.g3.zoosite.model.DwAnimalRescue;
import com.g3.zoosite.mapper.DwAnimalRescueMapper;
import com.g3.zoosite.service.IDwAnimalRescueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 动物救助信息表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-09-28
 */
@Service
public class DwAnimalRescueServiceImpl extends ServiceImpl<DwAnimalRescueMapper, DwAnimalRescue> implements IDwAnimalRescueService {
    @Autowired(required = false)
    DwAnimalRescueMapper dwAnimalRescueMapper;

    //图片服务器地址
    @Value("${image-server}")
    private String imageServer;

    //查询所有动物救助信息
    @Override
    public List<DwAnimalRescue> findAnimalRescues() {
        List<DwAnimalRescue> animalRescues =
                dwAnimalRescueMapper.selectList(null);
        for (int i=0;i<animalRescues.size();i++){
            DwAnimalRescue dwAnimalRescue = animalRescues.get(i);
            //拼接图片服务器地址和图片路径
            dwAnimalRescue.setImagePath(imageServer+dwAnimalRescue.getImagePath());
        }
        return animalRescues;
    }

    //按id查询动物救助信息
    @Override
    public DwAnimalRescue findAnimalRescue(Integer id) {
        DwAnimalRescue animalRescue = dwAnimalRescueMapper.selectById(id);
        //拼接图片服务器地址和图片路径
        animalRescue.setImagePath(imageServer+ animalRescue.getImagePath());
        return animalRescue;
    }
}
